package view;

import Model.Anggota;
import Model.Perpustakaan;
import java.awt.event.ActionEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class PanelTambahAnggota extends JPanel {
private JLabel labelKodeAnggota ;
private JTextField textKodeAnggota ;
private JLabel labelNama ;
private JTextField textNama ;
private JButton tombolSimpan ;
private JButton tombolBatal;

public PanelTambahAnggota(){
        
        setLayout(null);
        
      
        labelKodeAnggota = new JLabel("Id Anggota");
        labelKodeAnggota.setBounds(50, 120, 80, 20);
        this.add(labelKodeAnggota);
                
        textKodeAnggota = new JTextField();
        textKodeAnggota.setBounds(130, 120, 100, 20);
        this.add(textKodeAnggota);
                
        labelNama = new JLabel("Nama");
        labelNama.setBounds(50, 150, 80, 20);
        this.add(labelNama);
        
        textNama = new  JTextField();
        textNama.setBounds(130, 150, 200, 20);
        this.add(textNama);
                
        JPanel sv = new JPanel();
        tombolSimpan = new JButton("Simpan");
        tombolSimpan.setBounds(120, 300, 80, 20);
        sv.add(tombolSimpan);
        this.add(tombolSimpan);
        
        tombolSimpan.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
                try {
                    tombolSimpanAction();
                } catch (Exception ex) {
                    Logger.getLogger(PanelTambahAnggota.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
        
        JPanel csl = new JPanel();
        tombolBatal = new JButton("Batal");
        tombolBatal.setBounds(220, 300, 80, 20);
        sv.add(tombolBatal);
        this.add(tombolBatal);
        
        
        tombolBatal.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tombolBatalAction();
            }
        });
    }

        public void tombolSimpanAction() {
            
                Anggota anggota = new Anggota();
        try {
            anggota.setIdAnggota(textKodeAnggota.getText());
        } catch (Exception ex) {
            Logger.getLogger(PanelTambahAnggota.class.getName()).log(Level.SEVERE, null, ex);
        }
                anggota.setNama(textNama.getText());
                Perpustakaan.tambahAnggota(anggota);
                JOptionPane.showMessageDialog(this,
                        "id koleksi : "+anggota.getIdAnggota()+""+
                        "judul : "+anggota.getNama());
                        
            }
        
        
                public void tombolBatalAction(){
                        System.exit(0);
            }
}



